#include<bits/stdc++.h>
using namespace std;
int n,sum,ans1,ans2,ans,sum1,flag,t;
int a[200010],color[200010],m[200010];
void dfs(int x)
{
    if(x==n)
    {
		for(int i=2;i<=n;i++)
		{
			flag=0;
			for(int j=i-1;j>=1;j--)
			{
				if(color[i]==color[j]&&flag==0)
				{
					if(a[i]==a[j])
					{
						m[i]=a[i];
					}
					if(a[i]!=a[j])
					{
						m[i]=0;
					}
					flag=1;
				}
			}
			if(flag==0)
			{
				m[i]=0;
			}
		}
	}
	sum1=0;
	for(int i=2;i<=n;i++)
	{
		sum1=sum1+m[i];
	}
	sum=max(sum,sum1);
    if(x!=n)
    {
		color[x+1]=1;
		dfs(x+1);
		color[x+1]=2;
		dfs(x+1);
	}
}
int main()
{
	cin>>t;
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	for(int i=1;i<=t;i++)
	{
		cin>>n;
		sum=0;
		ans1=0;ans2=0;ans=0;sum1=0;flag=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	color[1]=1;
	dfs(1);
	color[1]=0;
	ans1=sum;
	sum=0;
	color[1]=2;
	dfs(1);
	color[2]=0;
	ans2=sum;
	if(ans1>ans2) ans=ans1;
	if(ans2>=ans1) ans=ans2;
	cout<<ans<<endl;
	}
	return 0;
}
